# -*- coding: utf-8 -*-

# 导入xadmin
import xadmin

# 从模型中导入所有模型
from .models import *

# 导入插件
from .plugins import *
# 导入管理View
from xadmin.views import ListAdminView
# 注册插件
xadmin.site.register_plugin(DemoPlugin, ListAdminView)
xadmin.site.register_plugin(QueryMenuPlugin, ListAdminView)
xadmin.site.register_plugin(QueryPlugin, ListAdminView)


# 导入Action
from .actions import *



# 班级管理页面配置
class ClassAdmin(object):

    # 管理列表页显示的字段
    # list_display = ('id', 'name') # version1
    list_display = ('name', )       # version2

# 注册班级管理页面 将班级模型和班级管理页面连接
xadmin.site.register(Class, ClassAdmin)


# 学科管理
class SubjectAdmin(object):

    list_display = ('name', )

xadmin.site.register(Subject, SubjectAdmin)

# ID卡Inline
class IDCardInline(object):
   model = IDCard


# 学生管理
class StudentsAdmin(object):

    list_display = ('name', 'sex', 'free', 'score', 'type', 'birthday', 'cls', 'subject', 'age')

    # 表单形式
    style_fields = {'subject': 'checkbox-inline'}

    # 被关联到IDCard表
    inlines = (IDCardInline, )

    # 搜索
    search_fields = ('name', )

    # 过滤
    list_filter = ('sex', 'free', 'score', 'type', 'birthday', 'cls', 'subject')

    demo_plugin = True

    demo_query_menu = True

    # 动作
    actions = [DemoAction, SubjectAction]


xadmin.site.register(Students, StudentsAdmin)


# ID卡管理
class IDCardAdmin(object):

    list_display = ('number', 'student')

xadmin.site.register(IDCard, IDCardAdmin)